package git.bankview.wl.report;

import java.util.*;
import java.sql.*;
import java.io.*;

import laya.semi.process.*;
import git.bankview.sl.report.ReportCommon;
import git.bankview.sl.report.ReportParameter;
import git.bankview.sl.report.SchdUtil;
import git.bankview.sl.report.ReportSchd;
import git.bankview.wl.bean.LogonBean;

import git.bankview.sl.db.*;

import org.apache.log4j.Logger;

public class ReportHandler
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(ReportHandler.class);
	
	public void execute(IProcessContext oCtx)
		throws Exception
	{
		List oParamList = (List)oCtx.getField("jasperParams");
		String[] vInputParamVal = (String[])oCtx.getField("jrParameters");
		LogonBean oLogon = (LogonBean)oCtx.getField("logon");
		
		ReportSchd oSchd = new ReportSchd();
		oSchd.setTransid((String)oCtx.getField("transid"));
		oSchd.setSchdtype(Integer.parseInt(((String[])oCtx.getField("schdtype"))[0]));
		oSchd.setSchdexport(((String[])oCtx.getField("jrExport"))[0]);
		
		Map paramMap = new HashMap();
		for (int paramIdx = 0; paramIdx < oParamList.size(); ++paramIdx)
		{
			ReportParameter param = (ReportParameter)oParamList.get(paramIdx);
			paramMap.put(param.getName(), vInputParamVal[paramIdx]);
		}
		
		paramMap.put(ReportCommon.GRP_SCHD_USER, oLogon.getUsername());
		oSchd.setReportParameterMap(paramMap);
		File outputFile = File.createTempFile("report", "." + oSchd.getSchdexport());
		
		SchdUtil.handleReport(oSchd, null, null, outputFile);
		oCtx.setField("outputFile", outputFile);
	}
}
